package com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.dao.Impl;
import com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.dao.ShowLeaverDao;
import com.yunzheng.studyLeaveSystem.modules.admin.search.trueSearch.entity.leaver;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class ShowLeaverDaoImpl implements ShowLeaverDao {
    public List<leaver> queryInformation() throws Exception {
        Connection connection = DBUtils.getCon();
        List<leaver> InformationList = new ArrayList<>();
        String sql = "select leave_date,leaver_name,leave_class,reason,term,direction from leaver where YEARWEEK(date_format(leave_date,'%Y-%m-%d')) = YEARWEEK(now()) ";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            leaver leaver = new leaver();
            leaver.setName(resultSet.getString("leaver_name"));
            leaver.setTerm(resultSet.getString("term"));
            leaver.setDirection(resultSet.getString("direction"));
            leaver.setLeave_date(resultSet.getString("leave_date"));
            leaver.setLeave_class(resultSet.getString("leave_class"));
            leaver.setReason(resultSet.getString("reason"));
            InformationList.add(leaver);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return InformationList;
    }
}
